package com.winning.sx.microframework.model.genericapi;

import com.winning.sx.microframework.common.constant.GenericApiConstant;
import com.winning.sx.microframework.model.exception.CustomException;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.util.Date;

@Data public class GenericApiInterfaceInfo implements ApiInterface{

    private Integer id;
    private String productionURL;
    private String name;
    private Integer ServerId;
    private String testURL;
    private String currentPattern;
    private String logWay;
    private String unit;
    private Integer SumCount;
    private String testOutputMessage;
    private String testReturnMessage;
    private Date CreateTime;
    private Date UpdateTime;
    private String state;
    private String validFlag;


    @Override
    public boolean state() throws CustomException {
        if(StringUtils.isEmpty(getState()))throw new CustomException(GenericApiConstant.ERROR_CODE_STATE_NOTNULL,"接口状态state为空！！！");
        if(StringUtils.equals("true",getState().trim()))return true;
        return false;
    }

    @Override
    public String url() {
        switch (getCurrentPattern()){
            case GenericApiConstant
                    .CURRENTPARTTEN_TEST:
                return getTestURL();
            case GenericApiConstant
                    .CURRENTPARTTEN_PRO:
                return  getProductionURL();
            default:return productionURL;
        }
    }

    @Override
    public int server() {
        return getServerId();
    }
}
